/*
 * GaseousPhase.cpp
 *
 *  Created on: 28 May 2011
 *      Author: allan
 */

#include "GaseousPhase.h"

// C++ includes
#include <numeric>

GaseousPhase::GaseousPhase() 
{}

GaseousPhase::GaseousPhase(const StringVector& species)
{
	SetSpecies(species);
}

GaseousPhase::~GaseousPhase() 
{}

void GaseousPhase::SetSpecies(const StringVector& species)
{
	Phase::SetSpecies(species);
}

const DoubleVector GaseousPhase::FugacityCoefficients(double T, double P, const DoubleVector& n) const
{
	DoubleVector fugacityCoeffs(species.size(), 1.0);
	
	return fugacityCoeffs;
}
	
const DoubleVector GaseousPhase::Fugacities(double T, double P, const DoubleVector& n) const
{
	DoubleVector fugacities(FugacityCoefficients(T, P, n));
	
	for(uint i = 0; i < n.size(); ++i)
		fugacities[i] *= P;
	
	return fugacities;
}

const String GaseousPhase::GetName() const
{
	return "Gaseous";
}

const DoubleVector GaseousPhase::ActivityCoefficients(double T, double P, const DoubleVector& n) const
{
	return FugacityCoefficients(T, P, n);
}

const DoubleVector GaseousPhase::Activities(double T, double P, const DoubleVector& n) const
{
	// The vector of activities of the gases
	DoubleVector a(FugacityCoefficients(T, P, n));
	
	// The total number of moles in the aqueous phase
	const double nT = std::accumulate(n.begin(), n.end(), 0.0);
	
	// Multiply each entry (i) in the vector (a) by pressure (P) and the molar fraction of the gas (i)
	for(uint i = 0; i < species.size(); ++i)
		a[i] *= P * n[i]/nT;
	
	return a;
}
